﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace Tanks
{
    class Tank
    {
        public Image tankImage = Properties.Resources.tank1;
        protected int xf = 10, yf = 10;
        protected float x = 10, y = 10;
        protected float dx, dy;
        public int speed = 5;
        public int X
        {
            set { x = value; }
            get { return (int)x; }
        }
        public int Y
        {
            set { y = value; }
            get { return (int)y; }
        }
        public int Dx
        {
            get { return (int)dx; }
        }
        public int Dy
        {
            get { return (int)dy; }
        }
        public bool Stop
        {
            get { return (Math.Abs(xf - x) <= tankImage.Width / 3) && (Math.Abs(yf - y) <= tankImage.Height / 3); }
        }

        public void Go()
        {
            if (x + (speed * dx) > tankImage.Width / 2 &&
                (x + (speed * dx) < MainForm.ActiveForm.Width - tankImage.Width) &&
                (y + (speed * dy) > tankImage.Height / 2) &&
                (y + (speed * dy) < MainForm.ActiveForm.Height - tankImage.Height))
            {
                x += (speed * dx);
                y += (speed * dy);
            }
        }
        public void Go(int xf, int yf)
        {
            this.xf = xf;
            this.yf = yf;
            dx = Math.Sign(xf - x) * (Math.Abs(xf - X) < Math.Abs(yf - Y) && (yf - Y) != 0 ? Math.Abs((xf - x) / (yf - y)) : 1);
            dy = Math.Sign(yf - y) * (Math.Abs(yf - Y) < Math.Abs(xf - X) && (xf - X) != 0 ? Math.Abs((yf - y) / (xf - x)) : 1);
            Go();
        }
    }
}
